<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Internet pizzeria - Check order status</title>
</head>
<body>	
<%@ include file="navigationMenu.jsp" %>
	<h2>Current orders</h2>
	<form method="post" action="cancelOrder">
	<table border='1'>
	<tr>
			<td>Order number</td>
			<td>Address</td>
			<td>Details</td>
			<td>Status</td>
			<td>Cancel</td>
	</tr>
	<c:forEach var="orderInfo" items="${currentOrderInfos}">
	<tr>
		<td>${orderInfo.order.id}</td>
		<td id="address${orderInfo.order.id}">${orderInfo.order.delivery.streetAndNumber},${orderInfo.order.delivery.zipCode},${orderInfo.order.delivery.city}</td>
		<td>
			<c:forEach var="orderPizza" items="${orderInfo.pizzas}">
			${orderPizza.quantity} x ${orderPizza.product.name} 
			<br/>
			</c:forEach>
			<hr/>
			<c:forEach var="orderDrink" items="${orderInfo.drinks}">
			${orderDrink.quantity} x ${orderDrink.product.name} 
			<br/>
			</c:forEach>
		</td>
		<td>${orderInfo.order.status}</td>
		<td><script type="text/javascript">
			var status = "${orderInfo.order.status}";
			if (status == "Awaiting preparation"){
				document.write('<a href="cancelOrder?orderId=${orderInfo.order.id}">Cancel order</a>');
			}
			else{
				document.write('N/A');
			}
			</script>
		</td>
	</tr>
	</c:forEach>
	</table>
	</form>	
	
	<br/>
	
	<h2>Previous orders</h2>
	<table border='1'>
	<tr>
			<td>Order number</td>
			<td>Address</td>
			<td>Details</td>
			<td>Status</td>
			<td>Ordered</td>
	</tr>
	<c:forEach var="orderInfo" items="${previousOrderInfos}">
	<tr>
		<td>${orderInfo.order.id}</td>
		<td id="address${orderInfo.order.id}">${orderInfo.order.delivery.streetAndNumber},${orderInfo.order.delivery.zipCode},${orderInfo.order.delivery.city}</td>
		<td>
			<c:forEach var="orderPizza" items="${orderInfo.pizzas}">
			${orderPizza.quantity} x ${orderPizza.product.name} 
			<br/>
			</c:forEach>
			<hr/>
			<c:forEach var="orderDrink" items="${orderInfo.drinks}">
			${orderDrink.quantity} x ${orderDrink.product.name} 
			<br/>
			</c:forEach>
		</td>
		<td>${orderInfo.order.status}</td>
		<td>${orderInfo.order.orderedDate}</td>
	</tr>
	</c:forEach>
	</table>	
</body>
</html>
